package com.fht.service.member.impl;

import com.fht.entity.MemberManager;
import com.fht.from.MemberFrom;
import com.fht.mapper.member.MemberManagerMapper;
import com.fht.service.member.MemberManagerService;
import com.fht.util.UnitConversionUtil;
import com.fht.vo.LayUITableVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Slf4j
@Service
public class MemberManagerServiceImpl implements MemberManagerService {

    @Resource
    public MemberManagerMapper memberManagerMapper;


    @Override
    public LayUITableVO<List<MemberManager>> findPage(Map<String, Object> map) {

        PageHelper.startPage((int) map.get("page"),(int) map.get("limit"));

        List<MemberManager> list = memberManagerMapper.findPage(map);
        for (MemberManager memberManager : list) {
            memberManager.setOpenCardDate(UnitConversionUtil.conversionDate(memberManager.getOpenCardDate()));
            memberManager.setIntegralString(UnitConversionUtil.conversion(memberManager.getIntegral()));
            memberManager.setConsumptionTotalString(UnitConversionUtil.conversion(memberManager.getConsumptionTotal()));
        }

        PageInfo<MemberManager> pageInfo = new PageInfo<>(list);

        LayUITableVO<List<MemberManager>> vo = new LayUITableVO<>();
        vo.setCount(pageInfo.getTotal());
        vo.setData(pageInfo.getList());

        return vo;

    }

    @Override
    public MemberManager selectById(String id) {
        return memberManagerMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional
    public void update(MemberManager memberManager) {

        memberManagerMapper.updateByPrimaryKeySelective(memberManager);
    }

    @Override
    @Transactional
    public void save(MemberManager memberManager) {

        memberManagerMapper.insertSelective(memberManager);

    }

    @Override
    @Transactional
    public void deleteById(String id) {

        memberManagerMapper.deleteByPrimaryKey(id);

    }
}
